package fileIO;

/*
 * 已实验方法有点yiwen delete() 与deleteOnExit() system.out.print
 * getAbsoluteFile() 与getAbsolutePath() and getCanonicalPath()
 * getFreeSpace()
 */

/*
 * 未实验方法
 * 
 * compareTo(File pathname) 
 */
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.IOException;

public class FileListTest {
	public static void main(String[] args) throws IOException {
//		listFilenameFilter();
//		listFilenameFilterAnonymous();
//		listFilesTest();
		test();
	}
	private static void test() {
		String s = "th";
		System.out.print(s+"\n");
		System.out.println(s);
	}

	private static void listFilenameFilterAnonymous() {
		File f = new File("/home/tarena/0heantai/book");
		String[] s = f.list(new FilenameFilter() {
			public boolean accept(File dir, String name) {//dir即f文件夹，name是f文件夹中每个文件的文字
				return name.endsWith(".pdf");
			}
		});
		for (int i = 0; i < s.length; i++) {
			System.out.println(s[i]);
		}

	}

	private static void listFilenameFilter() {
		class OnlyExt implements FilenameFilter {
			String ext;

			public OnlyExt(String ext) {
				this.ext = "." + ext;
			}

			public boolean accept(File dir, String name) {
				return name.endsWith(ext);
			}
		}

		File f = new File("/home/tarena/0heantai/book");
		FilenameFilter only = new OnlyExt("pdf");
		String[] s = f.list(only);
		for (int i = 0; i < s.length; i++) {
			System.out.println(s[i]);
		}
	}

	private static void listFilesTest() {
		File f = new File("/home/tarena/0heantai/book");
		File[] arr = f.listFiles(new FileFilter() {
			public boolean accept(File pathname) {
				return pathname.getName().matches(".*pdf");
			}
		});
		for (File file : arr) {
			System.out.println(file);
		}
	}

}
